package com.doupi.partner.rpc.exception;

import com.doupi.partner.util.RuntimeBusinessException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 统一系统异常拦截器
 */
public class WebExceptionHandler implements HandlerExceptionResolver {
	private static final Logger LOGGER = LoggerFactory.getLogger(WebExceptionHandler.class);
	private static final String ERROR_PAGE = "error";

	public ModelAndView resolveException(HttpServletRequest httpRequest, HttpServletResponse httpResponse, Object handler, Exception ex) {
		ModelAndView modelAndView = new ModelAndView();
		modelAndView.setViewName(ERROR_PAGE);
		RuntimeBusinessException.handlerSystemException(httpRequest, httpResponse, handler, ex, LOGGER);
		return modelAndView;
	}
}
